package com.zlyx.easy.core.tool;

import java.util.Collection;
import java.util.Map;
import java.util.Random;

import com.zlyx.easy.core.tool.EasyBuffer;
import com.zlyx.easy.core.tool.Ops;
import com.zlyx.easy.core.utils.DateUtils;

/**
 * @author zhaog
 * @version 创建时间：2018年11月2日 下午12:31:34
 * @ClassName 类名称
 * @Description 类描述
 */
public final class Console {

	static Random fontRandom = new Random();

	public static void at(Object o) {
		at(o, o);
	}

	public static void at(Object key, Object value) {
		log(EasyBuffer.at(key, value));
	}

	public static void current() {
		log(Ops.getMillis());
	}

	public static void date() {
		log(DateUtils.getNow());
	}

	public static void dateMs() {
		log(DateUtils.getNowMs());
	}

	public static void log(Object o) {
		println(null, o);
	}

	public static void log(Object... objs) {
		println(null, objs);
	}

	public static void log(String key, Object value) {
		println(key, value);
	}

	public static void log(String key, Object... objs) {
		println(key, objs);
	}

	public static void log(Collection<?> objs) {
		println(null, objs);
	}

	public static void log(String key, Collection<?> objs) {
		println(key, objs);
	}

	public static void log(Map<?, ?> map) {
		println(null, map);
	}

	public static void log(String key, Map<?, ?> map) {
		println(key, map);
	}

	public static void info(Class<?> tClass, Object... msg) {
		log(tClass.getName(), msg);
	}

	public static void info(Class<?> tClass, Collection<?> objs) {
		log(tClass.getName(), objs);
	}

	public static void info(Class<?> tClass, Map<?, ?> map) {
		log(tClass.getName(), map);
	}

	public static void info(Object target, String... msg) {
		log(target.getClass(), msg);
	}

	public static void info(Object target, Object[] msg) {
		log(target.getClass().getName(), msg);
	}

	public static void info(Object target, Collection<?> objs) {
		log(target.getClass().getName(), objs);
	}

	public static void info(Object target, Map<?, ?> map) {
		log(target.getClass().getName(), map);
	}

	private static void println(Object key, Object value) {
		if (Ops.isEmpty(value)) {
			value = "Value is Null!";
		}
		if (Ops.isNotEmpty(key)) {
			value = EasyBuffer.newString(key, " => ", value);
		}
		System.out.format("\33[%d;4m%s%n\033[0m", fontRandom.nextInt(7) + 30, value);
	}
}
